package com.qiqichangting.changting.controller;

import com.changting.changtingfile.common.MessageConst;

import com.qiqichangting.changting.pojo.Result;
import com.qiqichangting.changting.pojo.User;
import com.qiqichangting.changting.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/Register")
public class RegisterController {

    @Autowired
    private UserService userService;

    @RequestMapping("/findByUser")
    public Result findByUser(String username){
        User byUser = userService.findByUser(username);
        if (byUser!=null){
            return new Result(false,MessageConst.DELETE_MEMBER_FAIL,"该用户已存在");
        }
        return new Result(true,MessageConst.ADD_MEMBER_SUCCESS);
    }

    @RequestMapping("/register")
    public Result register(@RequestBody User user){
        boolean falg = userService.addUser(user);
        if (falg){
            return new Result(true, MessageConst.ADD_MEMBER_SUCCESS);
        }else {
            return new Result(true, MessageConst.DELETE_MEMBER_FAIL);
        }
    }
}
